// iOS SSL Pinning Bypass - Frida Script

// 在 Objective-C 的上下文中执行
ObjC.perform(function () {
    // 引入必要的类和协议
    var NSURLSession = ObjC.classes.NSURLSession;
    var NSURLSessionDelegate = ObjC.protocols.NSURLSessionDelegate;

    // Hook NSURLSession的dataTaskWithRequest方法
    Interceptor.attach(NSURLSession['- dataTaskWithRequest:completionHandler:'].implementation, {
        onEnter: function (args) {
            console.log("Bypassing SSL Pinning in dataTaskWithRequest");
        },
        onLeave: function (retval) {
            // 此处可以处理返回值，如果需要
        }
    });

    // Hook NSURLSession的delegate方法 - didReceiveChallenge
    var method = NSURLSessionDelegate['- URLSession:didReceiveChallenge:completionHandler:'].implementation;

    Interceptor.attach(method, {
        onEnter: function (args) {
            console.log("Received SSL Challenge");
            var completionHandler = new ObjC.Block(args[2]);

            // 信任所有证书
            completionHandler.invoke(0, 0); // 0 表示信任
        }
    });
});